package com.qfedu.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qfedu.dao.WeekDao;
import com.qfedu.entity.ResponseData;
import com.qfedu.entity.Week;
import com.qfedu.service.WeekSerivice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;
@Service
public class WeekSerivceImpl implements WeekSerivice {
    @Autowired
    private WeekDao weekDao;
    @Override
    public ResponseData<List<Week>> findAllWeek(int pageIndex,int pageSize) {
        PageHelper.startPage(pageIndex,pageSize);
        List<Week> weekList = weekDao.findAllWeek();
        PageInfo pageInfo = new PageInfo(weekList);
        int count = (int) pageInfo.getTotal();
        ResponseData<List<Week>> responseData = new ResponseData<>();
        responseData.setCode(0);
        responseData.setData(weekList);
        responseData.setCount(count);
        responseData.setMsg("ok");
        return responseData;
    }

    @Override
    public boolean addWeek(Week week) {
        int result = weekDao.addWeek(week);

        if(result >0){
            return true;
        }
        return false;
    }

    @Override
    public boolean deleteWeek(int id) {
        int result = weekDao.deleteWeek(id);
        if(result >0){
            return true;
        }
        return false;
    }

    @Override
    public boolean updateWeek(Week week) {
        int result = weekDao.updateWeek(week);
        if(result >0){
            return true;
        }
        return false;
    }

    @Override
    public Week findWeekById(int id) {
        return weekDao.findWeekById(id);
    }

}
